package com.example.wordcardjavaproject.controller;

import com.example.wordcardjavaproject.bean.User;
import com.example.wordcardjavaproject.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/vue-admin-template/user")
public class LoginController {

    @Resource
    UserService userService;

    @RequestMapping(value = "/logout", method = RequestMethod.POST)
    public Object logout(){
        Map<String,Object> resultMap=new HashMap<>();
        resultMap.put("code",20000);
        resultMap.put("data","success");
        return resultMap;
    }

    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public Object login(@RequestBody(required = false) User data) throws Exception {
//        System.out.println(data);
        User user = userService.login(data);
        Map<String,Object> resultMap=new HashMap<>();
        resultMap.put("code",20000);
        Map<String,Object > map=new HashMap<>();
        map.put("token","admin-token");
        map.put("user", user);
        resultMap.put("data",map);
        return resultMap;
    }

    @RequestMapping(value = "/info",method = RequestMethod.GET)
    public Object info(){
        Map<Object,Object> resultMap=new HashMap<>();
        Map<Object,Object> data=new HashMap<>();
        List<Object> roles=new ArrayList<>();

        resultMap.put("code",20000);
        data.put("avatar","https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif");
        data.put("introduction","I am a super administrator");
        data.put("name","Super Admin");
        roles.add("admin");
        data.put("roles",roles);
        resultMap.put("data",data);
        return resultMap;
    }
}
